unit settings;

interface

procedure SaveSettings(APort, AFolder: string);
procedure ReadSettings(out APort, AFolder: string);

implementation

uses
  SysUtils;

procedure SaveSettings(APort, AFolder: string);
var
  lFile: TextFile;
begin
  AssignFile(lFile, '.\settings.cfg');
  Rewrite(lFile);
  Writeln(lFile, 'Port=' + APort);
  Writeln(lFile, 'Directory=' + AFolder);
  CloseFile(lFile);
end;

procedure ReadSettings(out APort, AFolder: string);
var
  lFile: TextFile;
  S: string;
begin
  {$I-}
  AssignFile(lFile, '.\settings.cfg');
  FileMode := 0;  {Set file access to read only }
  Reset(lFile);
  {$I+}
  if  (IOResult = 0) then
  begin
    while not Eof(lFile) do
    begin
    Readln(lFile, S);
    if Pos('PORT', UpperCase(S)) > 0 then
      APort := Copy(S, Pos('=', S) + 1, Length(S) - (Pos('=', S)))
    else if Pos('DIRECTORY', UpperCase(S)) > 0 then
      AFolder := Copy(S, Pos('=', S) + 1, Length(S) - (Pos('=', S)));
    end;
  end;
  CloseFile(lFile);
end;

end.
